package com.hspedu.map_;

import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;

/**
 * @author DL5O
 * @version 1.0
 */

@SuppressWarnings("all")
public class TreeMap_ {
    public static void main(String[] args) {

        //使用默认的构造器，创建TreeMap
        /*
            按照传入的 k(String) 的大小进行排序
         */
//        TreeMap treeMap = new TreeMap();
        TreeMap treeMap = new TreeMap(new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                //按照默认的方法来进行比较
//                return ((String)o1).compareTo((String)o2);

                //按照长度的大小来进行排序
                return ((String)o1).length() -((String)o2).length();
            }
        });

        treeMap.put("jack","杰克");
        treeMap.put("tom","汤姆");
        treeMap.put("hsp","韩顺平");
        treeMap.put("kris","葵司");
        treeMap.put("smith","史密斯");
        System.out.println("treeMap=" + treeMap);

        /*
            treeMap={tom=汤姆, jack=葵司, smith=史密斯}
         */
    }
}
